﻿using Allin.Abp.AspNetCore.Components.Web.AntDesignTheme.Toolbars;
using Allin.Abp.AspNetCore.Components.Web.Theming;
using Allin.Abp.AspNetCore.Components.Web.Theming.Layout;
using Allin.Abp.AspNetCore.Components.Web.Theming.Routing;
using Allin.Abp.AspNetCore.Components.Web.Theming.Theming;
using Allin.Abp.AspNetCore.Components.Web.Theming.Toolbars;
using Volo.Abp.Modularity;

namespace Allin.Abp.AspNetCore.Components.Web.AntDesignTheme;

[DependsOn(
    typeof(AbpAspNetCoreComponentsWebThemingModule)
    )]
public class AbpAspNetCoreComponentsWebAntDesignThemeModule : AbpModule
{
    public override void ConfigureServices(ServiceConfigurationContext context)
    {
        ConfigureToolbarOptions();
        ConfigureRouterOptions();
        ConfigurePageHeaderOptions();
        ConfigureAntDesignTheme();
    }

    private void ConfigureToolbarOptions()
    {
        Configure<AbpToolbarOptions>(options =>
        {
            options.Contributors.Add(new AntDesignThemeBlazorToolbarContributor());
        });
    }

    private void ConfigureRouterOptions()
    {
        Configure<AbpRouterOptions>(options =>
        {
            options.AdditionalAssemblies.Add(typeof(AbpAspNetCoreComponentsWebAntDesignThemeModule).Assembly);
        });
    }

    private void ConfigurePageHeaderOptions()
    {
        Configure<PageHeaderOptions>(options =>
        {
            options.RenderBreadcrumbs = false;
        });
    }

    private void ConfigureAntDesignTheme()
    {
        Configure<AbpThemingOptions>(options =>
        {
            options.Themes.Add<AntDesignTheme>();

            if (options.DefaultThemeName == null)
            {
                options.DefaultThemeName = AntDesignTheme.Name;
            }
        });
    }
}

